package view
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.media.SoundChannel;
	
	public class CartFace extends MovieClip
	{
		private var soundChannel:SoundChannel;

		public function CartFace()
		{
			stop();
		}
		
		public function startSpeakMoving(soundChannel:SoundChannel):void {
			this.soundChannel = soundChannel;
			this.addEventListener(Event.ENTER_FRAME, this.checkSoundPeak);			
			this.gotoAndPlay(1);			
		}
		
		public function stopSpeakMoving(e:Event):void {
			this.removeEventListener(Event.ENTER_FRAME, this.checkSoundPeak);			
			this.gotoAndStop(1);
		}
		
		public function checkSoundPeak(e:Event) {
			//trace(this.soundChannel.leftPeak)
			if(this.soundChannel.leftPeak < Config.SpeakingActiveSoundLevel) {
				this.gotoAndStop(1);
				//trace('stopFace');
			} else {
				this.play();
				//trace('startFace');
			}
		}		
	}
}